package com.xl333.mysql.dao;

import com.xl333.mysql.model.Column;

import java.util.List;

/**
 * @author 七月的狮子
 * @date 2020/5/13
 */
public class ColumnDao {

    private static ColumnDao instance = null;

    private ColumnDao(){

    }

    public static ColumnDao getInstance(){
        if(instance == null){
            instance = new ColumnDao();
        }
        return instance;
    }

    public List<Column> queryBySchemaAndTable(String schema, String tableName){
        String sql = "select COLUMN_NAME name, DATA_TYPE dataType, CHARACTER_MAXIMUM_LENGTH length," +
                " NUMERIC_PRECISION numericPrecision, NUMERIC_SCALE numericScale, COLUMN_COMMENT comment, COLUMN_KEY columnKey" +
                " from `COLUMNS` where TABLE_SCHEMA = '" + schema + "' and TABLE_NAME = '" + tableName + "'";
        DaoManager<Column> daoManager = new DaoManager<>();
        return daoManager.query(sql, Column.class);
    }

}
